package com.ht.base.system.biz.client.impl;

import com.ht.base.system.biz.manager.AppSystemManager;
import com.ht.base.system.client.AppSystemClient;
import com.ht.base.system.common.pojo.bo.AppSystemBO;
import com.ht.base.system.common.pojo.qto.AppSystemQTO;
import org.base.common.appexception.ResultData;
import org.base.common.page.PageBO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author：hdengxian
 * @Date：2023/10/7 10:45
 */
@DubboService
@Component
public class AppSystemClientImpl implements AppSystemClient {
    @Resource
    private AppSystemManager appSystemManager;

    @Override
    public ResultData<Boolean> checkAppId(String appId, String secretKey) {
        return new ResultData<>(appSystemManager.checkAppId(appId, secretKey));
    }

    @Override
    public ResultData<Integer> insertData(AppSystemBO appSystem, AppSystemBO appSystemBO) {
        ResultData<Boolean> resultData = checkAppId(appSystem.getAppId(), appSystem.getSecretKey());
        ResultData result = new ResultData<>();
        if (!resultData.getData()) {
            result.setSuccess(false);
            result.setMessage("没有权限访问该接口");
            result.setData(0);
            return result;
        }
        Integer integer = appSystemManager.insertData(appSystemBO);
        result.setData(integer);
        return result;
    }

    @Override
    public ResultData<Boolean> updateDataById(AppSystemBO appSystemBO) {
        Boolean aBoolean = appSystemManager.updateDataById(appSystemBO);
        return new ResultData<>(aBoolean);
    }

    @Override
    public ResultData<Boolean> deleteById(Long id) {
        return new ResultData<>(appSystemManager.deleteById(id));
    }

    @Override
    public ResultData<Boolean> deleteByIds(Long[] ids) {
        return new ResultData<>(appSystemManager.deleteByIds(ids));
    }

    @Override
    public ResultData<AppSystemBO> findById(Long id) {
        return new ResultData<>(appSystemManager.findById(id));
    }

    @Override
    public ResultData<PageBO<AppSystemBO>> findDataForPage(AppSystemQTO qto) {
        return new ResultData<>(appSystemManager.findDataForPage(qto));
    }

}
